<?php echo $this->title($this->pageTitle) ?>

<?php if (!empty($this->category['description'])) : ?>
<div class="category-description"><?php echo $this->category['description'] ?></div>
<?php endif; ?>

<?php if (!empty($this->category['image_base'])) : ?>
<div class="category-image"><?php 
echo $this->imager('category' . $this->category['image_base'], array(
    'width'  => 550,
    'height' => 200,
    'alt' => $this->escape($this->category['image_base_title']),
    'seo' => $this->category['image_base_title']
));
?></div>
<?php endif; ?>

<?php if (!count($this->products)): ?>
    <p class="empty-query"><?php echo $this->translate('catalog')->__('There are no products matching your request'); ?></p>
<?php else : ?>


<?php
$reviewSummaryBox = $this->box('community/ReviewRating')
    ->setProductIds(array_keys($this->products));
?>

<div class="box">

<?php echo $this->render('index/product-listing-paging.phtml') ?>

<?php if ($this->mode == 'list' ): /* List listing */ ?>
    <ul class="product-listing product-listing-list">
    <?php foreach ($this->products as $prodId => $product) :
        $productUrl = $this->hurl(array(
            'product' => array('value' => $prodId, 'seo' => $product['key_word']),
            'controller' => 'catalog',
            'action' => 'product'
        ), false, true);
    ?>
        <li class="product-item">
            <div class="product-media">
                <?php
                $imagePath = isset($product['images'][$product['image_listing']]) ?
                    $product['images'][$product['image_listing']]['path'] : '';
                $imageTitle = isset($product['images'][$product['image_listing']]) ?
                    $product['images'][$product['image_listing']]['title'] : '';
                ?>
                <a href="<?php echo $productUrl ?>" 
                   title="<?php echo $this->escape($imageTitle) ?>"
                   class="product-image"
                ><?php echo $this->imager('/product' . $imagePath, array(
                    'width'  => 180, 
                    'height' => 180, 
                    'alt' => $this->escape($imageTitle), 
                    'seo' => $product['image_seo_name']
                ));
                ?></a>
            </div>
            <div class="product-content">
                
                <h4 class="product-name"><a href="<?php echo $productUrl ?>" 
                    title="<?php echo $this->escape($product['name']) ?>"
                ><?php echo $product['name'] ?></a></h4>
                
                <?php echo $this->price($product['price'],
                    isset($product['price_discount']) ? 
                        $product['price_discount'] : false
                ) ?>
                
                <?php echo $reviewSummaryBox->setProductId($product['id'])
                    ->setProductUrl($product['key_word'])
                    ->toHtml() ?>
                
                <div class="product-description">
                    <?php if ($product['short_description'] != '') :
                        echo $product['short_description'];
                    else :
                        echo $this->translate('catalog')->__('No description available');
                    endif ?>
                </div>
                
                <?php if ($product['is_saleable']): ?>
                    <?php echo $this->button($this->translate('catalog')->__('Add to cart'), array(
                        'class' => 'button btn-add-to-cart',
                        'rel' => 'nofollow',
                        'href' => $this->href('checkout/cart/add/productId/' . $prodId, true)
                    )) ?>
                <?php else: ?>
                    <div class="out-of-stock"><?php echo $this->translate('catalog')->__('Out of stock') ?></div>
                <?php endif ?>
                
                <p class="add-to">
                    <a href="<?php echo $this->href('/account/wishlist/add/id/' . $prodId, true)?>"
                        rel="nofollow"
                        title="<?php echo $this->translate('catalog')->__('Add to Wishlist') ?>"
                        class="add-to-wishlist"><span><span>
                        <?php echo $this->translate('catalog')->__('Add to Wishlist')?></span></span></a>
                    <br/>
                    <a href="<?php echo $this->href('/' . $this->catalogUrl . '/product-compare/add/product/') . $prodId ?>"
                        rel="nofollow"
                        title="<?php echo $this->translate('catalog')->__('Add to Сompare') ?>" 
                        class="add-to-compare"><span><span>
                        <?php echo $this->translate('catalog')->__('Add to Сompare')?></span></span></a>
                </p>
            </div>
        </li>
    <?php endforeach; ?>
    </ul>
<?php else : /* Grid listing */ ?>
    <table class="product-listing product-listing-table" id="product-listing-table">
    <?php 
    $i = 0;
    $columnCount = 3;
    foreach ($this->products as $prodId => $product) :
        $productUrl = $this->hurl(array(
            'product' => array('value' => $prodId, 'seo' => $product['key_word']),
            'controller' => 'catalog',
            'action' => 'product'
        ), false, true);
    ?>
        <?php if ($i%$columnCount == 0) : ?>
           <tr>
        <?php endif; ?>
        
            <td>
                <div class="product-item">
                    <?php
                    $imagePath = isset($product['images'][$product['image_listing']]) ?
                        $product['images'][$product['image_listing']]['path'] : '';
                    $imageTitle = isset($product['images'][$product['image_listing']]) ?
                        $product['images'][$product['image_listing']]['title'] : '';
                    ?>
                    <a href="<?php echo $productUrl ?>" 
                       class="product-image"
                       title="<?php echo $this->escape($imageTitle) ?>"
                    ><?php echo $this->imager('/product' . $imagePath, array(
                        'width'  => $this->config()->image->product->widthSmall,
                        'height' => $this->config()->image->product->heightSmall,
                        'alt' => $this->escape($imageTitle), 
                        'seo' => $product['image_seo_name']
                    ));
                    ?></a>
                    
                    <h4 class="product-name"><a href="<?php echo $productUrl ?>" 
                        title="<?php echo $this->escape($product['name']) ?>"
                        ><?php echo $product['name'] ?></a></h4>
                    
                    <?php echo $this->price($product['price'], 
                        isset($product['price_discount']) ? 
                            $product['price_discount'] : false
                    ) ?>
                    
                    <?php echo $reviewSummaryBox->setProductId($product['id'])
                        ->setProductUrl($product['key_word'])
                        ->setSmallStars(true)
                        ->toHtml() ?>
                    
                    <?php if ($product['is_saleable']): ?>
                        <?php echo $this->button($this->translate('catalog')->__('Add to cart'), array(
                            'class' => 'button btn-add-to-cart',
                            'rel' => 'nofollow',
                            'href' => $this->href('checkout/cart/add/productId/' . $prodId, true)
                        )) ?>
                    <?php else: ?>
                        <div class="out-of-stock"><?php echo $this->translate('catalog')->__('Out of stock') ?></div>
                    <?php endif ?>
                    
                    <p class="add-to">
                        <a href="<?php echo $this->href('/account/wishlist/add/id/' . $prodId, true)?>"
                            rel="nofollow"
                            title="<?php echo $this->translate('catalog')->__('Add to Wishlist') ?>"
                            class="add-to-wishlist"><span><span>
                            <?php echo $this->translate('catalog')->__('Add to Wishlist')?></span></span></a>
                        <br/>
                        <a href="<?php echo $this->href('/' . $this->catalogUrl . '/product-compare/add/product/') . $prodId ?>"
                            rel="nofollow"
                            title="<?php echo $this->translate('catalog')->__('Add to Сompare') ?>" 
                            class="add-to-compare"><span><span>
                            <?php echo $this->translate('catalog')->__('Add to Сompare')?></span></span></a>
                    </p>
                </div>
            </td>
        
        <?php $i++;
        
        if ($i%$columnCount==0) : ?>
           </tr>
        <?php endif;
    
    endforeach;
    
    if ($i % $columnCount != 0) :
        for($i; $i % $columnCount; $i++): ?>
            <td class="empty-cell">&nbsp;</td>
        <?php 
        endfor;?>
        </tr>
    <?php endif; ?>
    
    </table>
    
    <script type="text/javascript">
        decorateTable('product-listing-table');
    </script>
<?php endif; ?>

<?php echo $this->render('index/product-listing-paging.phtml'); ?>
</div>

<?php endif; ?>

